package pxene.phantomJs;

import java.util.ArrayList;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;

public class ProxyTest {
	public static void main(String[] args) {
		System.setProperty("phantomjs.binary.path", "C:/Users/chenjinghui/Desktop/phantomjs-2.1.1-windows/bin/phantomjs.exe");

		WebDriver driver = new PhantomJSDriver();
		driver.get("http://www.autohome.com.cn/beijing/");
		String title = driver.getTitle();

		long t1 = System.currentTimeMillis();
		
		//设置user agent
		String userAgent = "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1";
		System.setProperty("phantomjs.page.settings.userAgent", userAgent);
		
		//设置ip 代理
		ArrayList<String> cliArgsCap = new ArrayList<String>();
//		cliArgsCap.add("--proxy=localhost:8080");
//		cliArgsCap.add("--proxy-auth=username:password");
//		cliArgsCap.add("--proxy-type=http");
		cliArgsCap.add("--load-images=false"); //不加载图片
		DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
		capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
		
		WebDriver driver1 = new PhantomJSDriver(capabilities); 
		driver1.get("http://www.autohome.com.cn/beijing/");
		System.out.println(title);
		
		long t2= System.currentTimeMillis();
		
		System.out.println(t2-t1);
	}
}
